home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fdform18.zip / AUXDOS.PAS next >
Pascal/Delphi Source File  |  1991-07-21  |  3KB  |  89 lines

  1. {$A+,B-,D+,E-,F-,I-,L+,N-,O-,R-,S-,V-,X+}
  2.  
  3. UNIT AuxDos;
  4.  
  5. {Auxiliary DOS-Interface-Routines}
  6. {Copyright (c) 1990-1991, Christoph H. Hochstätter}
  7. {Written in Turbo-Pascal 6.0}
  8.  
  9. INTERFACE
  10.  
  11. USES dos;
  12.  
  13. {File open mode and sharing constants}
  14.  
  15. CONST OReadOnly = 0;
  16.   OWriteOnly    = 1;
  17.   OReadWrite    = 2;
  18.   OCompatibility= $00;
  19.   ODenyAll      = $10;
  20.   ODenyWrite    = $20;
  21.   ODenyRead     = $30;
  22.   ODenyNone     = $40;
  23.   ONoInheritance= $80;
  24.  
  25. {DOS-File-Handles}
  26.  
  27. CONST StdNulHandle = 0;
  28.   StdOutHandle     = 1;
  29.   StdErrHandle     = 2;
  30.  
  31. VAR StdErr        : Text;                       {Define a file variable for standard error output}
  32.     old1B         : Pointer;                                       {Save old Ctrl-Break-Interrupt}
  33.     old23         : Pointer;                                     {Save Old abnormal End Procedure}
  34.  
  35. CONST ExitRequest : Boolean   = FALSE;                                       {Ctrl-Break pressed?}
  36.  
  37. PROCEDURE CtrlBreak;
  38. PROCEDURE EndProgram(x: Byte;s: String);
  39. PROCEDURE DefExitProc;
  40. PROCEDURE IgnoreInt;
  41.  
  42. IMPLEMENTATION
  43.  
  44.   PROCEDURE CtrlBreak; Assembler;                     {Don't invoke directly (or go to neverland)}
  45.   ASM
  46.     push    ds                 {Save DS}
  47.     {$IFOPT G+}
  48.     push    seg @data          {Push data-segment on stack}
  49.     pop     ds                 {Pop it in DS}
  50.     {$ELSE}
  51.     push    ax                 {Save AX, because it is interrupt}
  52.     mov     ax,seg @data       {Get data segment in AX}
  53.     mov     ds,ax              {Put it in DS}
  54.     pop     ax                 {Restore AX}
  55.     {$ENDIF}
  56.     mov     ExitRequest,True   {Set ExitRequest}
  57.     pop     ds                 {Restore DS}
  58.     iret                       {Exit}
  59.   END;
  60.  
  61.   PROCEDURE IgnoreInt; Assembler;
  62.   ASM
  63.     iret
  64.   END;
  65.  
  66.   PROCEDURE EndProgram;
  67.   BEGIN
  68.     IF ExitRequest THEN BEGIN
  69.       WriteLn(stderr,#13#10,s);
  70.       Halt(x);
  71.     END;
  72.   END;
  73.  
  74.   PROCEDURE DefExitProc;                                                  {Default Exit-Procedure}
  75.   BEGIN
  76.     SetIntVec($1B,old1B);                                       {Restore old Ctrl-Break-Procedure}
  77.     SetIntVec($23,old23);                                   {Restore old abnormal abort Procedure}
  78.     ExitProc:=NIL;
  79.   END;
  80.  
  81. BEGIN
  82.   move(Output,stderr,SizeOf(stderr));           {Copy Standard-Output File to Standard-Error File}
  83.   TextRec(stderr).Handle:=StdErrHandle;                      {Standard-Error is DOS-File-Handle 2}
  84.   TextRec(stderr).BufPtr:=@TextRec(stderr).Buffer;                            {set our own Buffer}
  85.   GetIntVec($1B,old1B);                                            {Save old Ctrl-Break interrupt}
  86.   GetIntVec($13,old23);
  87.   ExitProc:=@DefExitProc;                             {Restore Ctrl-Break-Interrupt, when exiting}
  88. END.
  89.